package com.cloud.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.baomidou.mybatisplus.annotation.*;
import com.cloud.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.Size;
import java.util.List;

/**
 * 用户对象 sys_user_info
 *
 * @author yzj
 */
@Data
@Schema(name = "用户对象", description = "系统管理")
@TableName("sys_user_info")
public class SysUser extends BaseEntity {

    @TableId(value = "user_id", type = IdType.AUTO)
    private Long userId;

    @Schema(description = "部门编号")
    private Long deptId;

    @Schema(description = "部门名称")
    @TableField(exist = false)
    @Excel(name = "部门名称", needMerge = true, width = 15)
    private String deptName;

    @Schema(description = "账户名称")
    @Excel(name = "账户名称", needMerge = true, width = 15)
    private String userName;

    @Schema(description = "用户昵称")
    @Excel(name = "用户昵称", needMerge = true, width = 15)
    private String nickName;

    @Schema(description = "用户邮箱")
    @Excel(name = "用户邮箱", needMerge = true, width = 15)
    private String email;

    @Schema(description = "手机号码")
    @Excel(name = "手机号码", needMerge = true, width = 15)
    private String phone;

    @Schema(description = "值班电话")
    @Excel(name = "值班电话", needMerge = true, width = 15)
    private String dutyPhone;

    @Schema(description = "用户性别(0=男,1=女,2=未知)")
    @Excel(name = "用户性别(男,女,未知)", needMerge = true, width = 15, replace = {"男_0", "女_1", "未知_2"})
    private String sex;

    @Schema(description = "用户头像")
    private String avatar;

    @Schema(description = "用户类型(系统用户)")
    @Excel(name = "用户类型(系统用户)", needMerge = true, width = 15, replace = {"系统用户_00"})
    private String userType;

    @Schema(description = "密码")
    @Excel(name = "密码", needMerge = true, width = 25)
    private String password;

    @Schema(description = "帐号状态(0=正常,1=停用)")
    private Integer status;

    @Schema(description = "备注")
    @Excel(name = "备注", needMerge = true, width = 20)
    private String remark;

    @Schema(description = "删除标识（0代表存在 1代表删除）", hidden = true)
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    private Integer deleted;

    @Schema(description = "系统编号")
    @TableField(exist = false)
    private String sysCode;

    @Schema(description = "用户关联/岗位", hidden = true)
    @TableField(exist = false)
    private String postNames;

    @Schema(description = "用户关联/角色", hidden = true)
    @TableField(exist = false)
    private String roleNames;

    @Schema(description = "部门对象")
    @TableField(exist = false)
    private SysDept dept;

    @Schema(description = "角色ID组", hidden = true)
    @TableField(exist = false)
    private Long[] roleIds;

    @Schema(description = "岗位ID组", hidden = true)
    @TableField(exist = false)
    private Long[] postIds;

    @ExcelCollection(name = "授权信息")
    @TableField(exist = false)
    private List<SysUserAuth> userAuthList;

    public SysUser() {
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    public String getNickName() {
        return nickName;
    }

    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    public String getUserName() {
        return userName;
    }

    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    public String getEmail() {
        return email;
    }

    @NotBlank(message = "手机号不能为空")
    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    public String getPhone() {
        return phone;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("userId", getUserId())
                .append("deptId", getDeptId())
                .append("userName", getUserName())
                .append("nickName", getNickName())
                .append("email", getEmail())
                .append("phone", getPhone())
                .append("dutyPhone", getDutyPhone())
                .append("sex", getSex())
                .append("avatar", getAvatar())
                .append("userType", getUserType())
                .append("password", getPassword())
                .append("status", getStatus())
                .append("deleted", getDeleted())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .append("remark", getRemark())
                .toString();
    }
}
